import time
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path="chromedriver.exe")

# driver =webdriver.Chrome #创建浏览器对象

# 2.输入网址
driver.get("https://hmshop-test.itheima.net/")
# 3.页面信息操作
# 3.页面信息操作
driver.maximize_window()
# # 暂停3秒
time.sleep(3)
# 通过超链接定位页面元素,打开登录界面
driver.find_element(By.PARTIAL_LINK_TEXT, value="登录").click()
# # 暂停2秒
time.sleep(2)
# 通过XPATH路径+属性定位输入账户,密码，验证码
driver.find_element(By.XPATH, "//input[@id='username']").send_keys("17877837620")
# # 暂停1秒
time.sleep(1)
driver.find_element(By.XPATH, "//input[@id='password']").send_keys("QQ196610")
# # 暂停1秒
time.sleep(1)
driver.find_element(By.XPATH, "//input[@id='verify_code']").send_keys("8888")
# 通过name属性定位连接
driver.find_element(By.NAME, value="sbtbutton").click()

# 获取所有Cookie
cookies = driver.get_cookies()
print("cookies内容为:", cookies)
# 转换为requests可用的字典格式
cookies_dict = {cookie['name']: cookie['value'] for cookie in cookies}
print("Cookies Dictionary:", cookies_dict)

# # 暂停3秒
time.sleep(3)
# driver.quit()
